using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace DataStructure
{
    class Test1
{
    public static List<string> ReadFile(string filename)
    {
        FileStream fs = new FileStream(filename, FileMode.Open);
        StreamReader sr = new StreamReader(fs);
        List<string> list = new List<string>();

        while (!sr.EndOfStream)
        {
            string contents = sr.ReadLine().Trim();
            int start = FirstCharacterIndex(contents,0);
            
            for (int i = start+1; i <= contents.Length;)
            {
                if(i ==contents.Length || !Char.IsLetter(contents[i]))
                {
                    string word = contents.Substring(start,i-start).ToLower();
                    list.Add(word);
                    start = FirstCharacterIndex(contents,i);
                    i = start + 1 ;
                }
                else
                    i++;
            }
        }

        fs.Close();
        sr.Close();

        return list;
    }

    //寻找字符串s，从start的位置开始的第一个字母字符的位置
    private static int FirstCharacterIndex(string s, int start)
    {
        for (int i = start; i < s.Length; i++)
        {
            if (Char.IsLetter(s[i]))
            {
                return i;
            }
        }
        return s.Length;
    }
}
}